import { _decorator, Label, sp, Sprite, SpriteFrame } from 'cc';
import { BaseUI } from '../../framework/base/BaseUI';
const { ccclass, property } = _decorator;

@ccclass('UIRolue')
export class UIRolue extends BaseUI {
    @property([SpriteFrame])
    texts:SpriteFrame[] = [
    ]
    aniIndex:number = 0;
    isHideBtn:boolean = false;
    showIndex:number = null;
    public init(param1?: any, param2?: any, param3?: any, param4?: any, param5?: any): void {
        this.isHideBtn = param1;
        this.showIndex = param2;
    }
    start() {
        this.findChilds("btnCloseView").onClick(this.onClickClose,this)
        this.findChilds("guize").getComponent(sp.Skeleton).setAnimation(0,"animation",false)
        this.findChilds("btnNodes").active = !this.isHideBtn;
        if( this.showIndex>=0){
            this.aniIndex = this.showIndex;
            this.refreshAniUI() 
        }
    }
    onClickLeft(){
        this.aniIndex--;
        if(this.aniIndex<=0){
            this.aniIndex = 0;
        }
        this.refreshAniUI()
    }
    onClickRight(){
        this.aniIndex++;
        if(this.aniIndex>this.texts.length-1){
            this.aniIndex = this.texts.length-1;
        }
        this.refreshAniUI()
    }
    refreshAniUI(){
        this.findChilds("pageNum").getComponent(Label).string = (this.aniIndex+1)+"/"+this.texts.length;
        this.findChilds("btnRigth").active = !(this.aniIndex==this.texts.length-1);
        this.findChilds("btnLeft").active = !(this.aniIndex==0);
        this.findChilds("guize").getComponent(sp.Skeleton).setAnimation(0,"guize"+(this.aniIndex+1),true)
        this.findChilds("tip").getComponent(Sprite).spriteFrame = this.texts[this.aniIndex]
    }
    onClickClose(){
        this.showIndex = null;
        this.closeUI() 
    }
    protected onEnable(): void {
      
    }

   
}


